package com.quantdo.demo.action;

import org.eclipse.jface.action.Action;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PartInitException;

import com.quantdo.demo.edit.TomcatManageEditor;
import com.quantdo.demo.edit.TomcatManageEditorInput;

public class OpenTomcatManageAction extends Action {
	private IWorkbenchWindow window;
	public static final TomcatManageEditorInput EDITOR_INPUT = new TomcatManageEditorInput();
	public OpenTomcatManageAction(IWorkbenchWindow window) {
		super();
		this.window = window;
		setText("&Tomcat管理@Ctrl+Alt+T");
		setToolTipText("Tomcat");
	}

	@Override
	public void run() {
		if (null == window) return;
		IEditorPart editor = window.getActivePage().findEditor(EDITOR_INPUT);
		if(null != editor){
			window.getActivePage().bringToTop(editor);
		}
		else{
			try {
				window.getActivePage().openEditor(EDITOR_INPUT,TomcatManageEditor.class.getName());
			} catch (PartInitException e) {
				e.printStackTrace();
				System.out.printf("文件不存在\n");
			}
		}
	}

}
